package com.brspace.qualitycontrol.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.brspace.qualitycontrol.entity.Duty;
import com.brspace.qualitycontrol.entity.vo.DutyVo;
import com.brspace.qualitycontrol.mapper.DutyMapper;
import com.brspace.qualitycontrol.service.DutyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-04-29
 */
@Service
public class DutyServiceImpl extends ServiceImpl<DutyMapper, Duty> implements DutyService {

    @Override
    public List<DutyVo> getData() {
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");

        List<DutyVo> dutyVos = new ArrayList<>();
        List<Duty> duties = baseMapper.selectList(new QueryWrapper<Duty>().select("name").orderByAsc("sort_number").last("limit 4"));
            for (int a = 0 ;a<4;a++){
                Calendar c = Calendar.getInstance();
                c.add(Calendar.DAY_OF_MONTH, a);
                DutyVo dutyVo = new DutyVo();
                dutyVo.setDate(sf.format(c.getTime()));
                dutyVo.setTitle(duties.get(a).getName());
                dutyVos.add(dutyVo);
            }
        return dutyVos;
    }
}
